package com.lk.lkappearance.controller;

import com.lk.lkappearance.common.AbstractBaseController;
import com.lk.lkappearance.model.User;
import com.lk.lkappearance.service.UserService;
import com.lk.lkappearance.utills.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/api/user")
public class UserController extends AbstractBaseController {


    @Autowired
    private UserService userService;

    /**
     * 新增员工
     * @param user
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public Map<String,Object> add(@RequestBody User user) {

        log.info("新增员工");

        if (StringUtils.isEmpty(user.getUserName())) {
            return fail("请输入员工用户名").getResult();
        }
        return userService.add(user);
    }

    @PutMapping("/modify/{id}")
    public Map<String,Object> modify(@PathVariable("id") String id,@RequestBody User user){
        log.info("修改员工信息");
        return userService.modify(user);
    }

    /**
     * 查看员工列表
     * @param user
     * @return
     */
    @ResponseBody
    @PostMapping("/getList")
    public Map<String,Object> list(@RequestBody User user){
         return userService.getList(user);
    }

    /**
     * 在线人数
     * @return
     */
    public Map<String,Object> onlineCount() {
        return  userService.onlineNum();
    }









}
